/********************************************************/
/*	LuaScript class by George Chew						*/
/*	For use in GeorgeLib								*/
/*	Created Mar 2013									*/
/*														*/
/*	Version 0001										*/
/********************************************************/

#ifndef __LUASCRIPT_H__
#define __LUASCRIPT_H__

#include "stdafx.h"
#include "Logger.h"
#include <cstdarg>	// stdarg.h for argument list

#define LUA_BUILD_AS_DLL

extern "C"
{
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
}

#define LuaScript GeorgeLib::_LuaScript::getInstance()

namespace GeorgeLib
{

	/*		How to use this class 		*/
	// Lua->LoadFile("mylua.lua");
	// int a = Lua->getFunctioni("func", "ifb", 234, 26.43, true);

	class DLLEXPORT _LuaScript
	{
	private:
		static	_LuaScript*	LuaScript_Instance;	// Singleton Instance

	public:
		static	lua_State*	theLuaState;		// Define the Lua Stat

		_LuaScript(void);	// Constructor
		~_LuaScript(void);	// Destructor

		// Get the singleton instance of this class 
		static	_LuaScript*	getInstance(void);

		void		NewState(void);

		// Initialise a file to use
		// You are able to use getFunction and getVariable only after
		// a file is initialised
		bool		LoadFile(char * FileName);

		// Get results from a function in your file
		// FuncName		:	the name of your function in your .lua file
		// ParamTypes	:	the types of your arguments passed
		//					'b' : boolean
		//					'i' : int
		//					'f' : float
		//					'd' : double
		//					's' : char* (c-string)
		//
		// Example call :
		// int a = Lua->getFunctioni("func", "bifds", true, 5, 5.5, 5.55, "five");
		int			getFunctioni(char * FuncName, char * ParamTypes, ...);
		float		getFunctionf(char * FuncName, char * ParamTypes, ...);
		double		getFunctiond(char * FuncName, char * ParamTypes, ...);
		char*		getFunctions(char * FuncName, char * ParamTypes, ...);
		int			getFunctionb(char * FuncName, char * ParamTypes, ...);

		// Get a variable from your file
		// VarName		:	the name of your variable (duh)
		//
		// Example call:
		// int a = Lua->getVariablei("variable");
		int			getVariablei(char * VarName);
		float		getVariablef(char * VarName);
		double		getVariabled(char * VarName);
		char*		getVariables(char * VarName);
		int			getVariableb(char * VarName);

		// Extra function to relieve code readability, not exported to the DLL
		friend	void		getFunctionParamLoop(char * ParamTypes, int & ParamAmount, va_list & Arguments);
	};

} // namespace GeorgeLib

#endif // __LUASCRIPT_H__ //